/*
 * EditShapePointsAction.java
 * 
 * Copyright 2009 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.admin.actions;

import java.awt.geom.Point2D;
import java.util.List;
import org.fpdev.core.basenet.BLink;
import org.fpdev.core.data.SpatialDataConnection.LinkAttr;
import org.fpdev.apps.admin.AdminClient;

/**
 *
 * @author demory
 */
public class EditShapePointsAction implements ACAction {

  private BLink link_;
  private List<Point2D.Double> oldShpPtList_,  newShpPtList_;

  public EditShapePointsAction(BLink link, List<Point2D.Double> oldShpPtList) {
    link_ = link;
    oldShpPtList_ = oldShpPtList;
    newShpPtList_ = link.getShapePointsList();
  }

  public boolean doAction(AdminClient ac) {
    link_.setShapePoints(newShpPtList_);
    link_.setLengthFeet(link_.getMeasuredLength());

    ac.getEngine().getDataPackage().getSpatialDataConn().modifyLink(link_, new LinkAttr[] { LinkAttr.SHAPE, LinkAttr.LEN });
    return true;
  }

  public boolean undoAction(AdminClient ac) {
    link_.setShapePoints(oldShpPtList_);
    link_.setLengthFeet(link_.getMeasuredLength());

    ac.getEngine().getDataPackage().getSpatialDataConn().modifyLink(link_, new LinkAttr[] { LinkAttr.SHAPE, LinkAttr.LEN });
    return true;
  }

  public String getName() {
    return "Edit Link Curvature";
  }
}
